package robocup.component.infotypes;

/**
 * This class informs abour messages, which were shouted by other players.
 */
public class PlayerSayInfo
    extends AuralInfo {

  /**
   * The relative direction of the hearde message.
   */
  private double  direction;

  /**
   * The message itself.
   */
  private String  message;

  /**
   * A flag indicating, that the message was sent by a teammate.
   */
  private boolean our    = false;

  /**
   * The number of the sender.
   */
  private int     number = -1;

  /**
   * An info-object holding the heared message of another player
   * 
   * @param iCycle -
   *          the time, when it was heared
   * @param iDirection -
   *          from which direction it was heared
   * @param iMessage -
   *          the message
   */
  public PlayerSayInfo(
      final int iCycle,
      final double iDirection,
      String iMessage) {

    super(iCycle);
    this.direction = iDirection;
    if (iMessage != null) {
      if (iMessage.startsWith("\"")) {
        iMessage = iMessage.substring(1, iMessage.length() - 1);
      }
    }
    this.message = iMessage;
    this.infoType = Info.TYPE_AURAL_PSI;
  }

  /**
   * @return Returns the direction.
   */
  public double getDirection() {

    return this.direction;
  }

  /**
   * @return Returns the message.
   */
  public String getMessage() {

    return this.message;
  }

  /**
   * @return A debug-string for this info-object.
   */
  @Override
  public String toString() {

    return ("PlayerMessage: " + this.direction + ", " + this.message);
  }

  /**
   * Sets the direction from where this message was heared.
   * 
   * @param direction -
   *          the relative direction.
   */
  public void setDirection(final double direction) {

    this.direction = direction;
  }

  /**
   * Sets the heared message.
   * 
   * @param message
   */
  public void setMessage(String message) {

    if (message != null) {
      if (message.startsWith("\"")) {
        message = message.substring(1, message.length() - 1);
      }
    }
    this.message = message;
  }

  /**
   * Checks, whether the sender belongs to our team or not.
   * 
   * @return true, if sender is a teammate.
   */
  public boolean isOur() {

    return this.our;
  }

  /**
   * Sets the sender of the message to be a teammate or not.
   * 
   * @param our -
   *          true if teammate, else opponent.
   */
  public void setOur(final boolean our) {

    this.our = our;
  }

  /**
   * @return Returns the number of the sender.
   */
  public int getNumber() {

    return this.number;
  }

  /**
   * Sets the number of the sender.
   * 
   * @param number
   */
  public void setNumber(final int number) {

    this.number = number;
  }
}
